<?php
echo date("Y-m-d H:i:s").PHP_EOL;
$arr = [
	'aps' => 'https://www.aipanshi.com',
	'baidu' => 'https://www.baidu.com',
	'hello' => 'https://www.helloweba.net/php/581.html',
	'sf' => 'https://segmentfault.com/a/1190000018404357?utm_source=sf-related',
];

foreach($arr as $key=>$url){
    //创建多个子进程
    $process = new swoole_process(function(swoole_process $worker) use($key,$url){
        $content = bazhan($key,$url);
		//echo '处理了：'.$key;
    },true);

    $pid = $process->start();
    $workers[$pid] = $process;
}

/**
foreach ($workers as $process) {
    echo $process->read();
}
*/

function bazhan($name,$url){
	sleep(2);
	$ch = curl_init();
	curl_setopt($ch, CURLOPT_URL, $url);
	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); 
	curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); 
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

	$output = curl_exec($ch);
	file_put_contents($name.'.html',$output);
}


echo date("Y-m-d H:i:s").PHP_EOL;